package com.teach.servlet.admin;

import com.teach.dao.CountryInfoDAO;
import com.teach.dao.SportingEventsDAO;
import com.teach.dao.impl.CountryInfoDAOImpl;
import com.teach.dao.impl.SportingEventsDAOImpl;
import com.teach.entity.CountryInfo;
import com.teach.entity.SportingEvents;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * -
 * 当前的项目名：medal-2022
 *
 * @author ZT
 * @data 2022/5/8 20:21
 **/
@WebServlet("/admin/sporting-update.let")
public class SportingEventsUpdateServlet extends HttpServlet {
    private SportingEventsDAO dao = new SportingEventsDAOImpl();

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.reset();
        response.setContentType("application/json;charset=UTF-8");
        try {

            //将前端传递过来的表单数据设置到实体对象中
            //注意:如果实体属性是非String的,则需要进行转换
            //注意: 该步骤适当加入校验
            SportingEvents e = new SportingEvents();

           e.setSeId(Integer.valueOf(request.getParameter("seId")));
            e.setSeName(request.getParameter("seName"));
            e.setSeDesc(request.getParameter("seDesc"));


            try {
                dao.updateById(e);
                response.getWriter().print("{\"ok\":true}");
            } catch (Exception ex) {
                throw new ServletException("国家代码不能重复", ex);
            }

        }catch (Exception ex){
            response.getWriter().print("{\"ok\":false,\"msg\":\""+ex.getMessage()+"\"}");
        }

        response.flushBuffer();
    }
}
